package com.irany.component;

import com.irany.App;
import org.openqa.selenium.WebDriver;

import java.util.ArrayList;

/**
 * @author shujian.ou
 * @since 2021/5/17 0017 16:06
 */
public abstract class AbstractCollector implements ICollector {

    private App app;

    /**
     * 窗口处理索引
     */
    private Integer handlerIndex;

    @Override
    public void close() {
        if (getDriver().getWindowHandles().size() <= 1) {
            return;
        }
        getDriver().close();
        getDriver().switchTo().window(new ArrayList<>(getDriver().getWindowHandles()).get(0));
    }

    public AbstractCollector(App app) {
        this.app = app;
    }

    protected WebDriver getDriver() {
        return app.getDriver();
    }

    public App getApp() {
        return app;
    }
}
